<template>
    {{#if ctrl.psSysPFPlugin}}
    {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
    {{else}}
    <AppWizardPanel
        :class="classNames"
        :id="controlID"
        :showStepBar="model.showStepBar"
        :buttonCaption="model.buttonCaption"
        :wizardForms="model.wizardForms"
        :wizardSteps="model.wizardSteps"
        :activeEditForm="store.activeEditForm"
        :stepTags="store.stepTags"
        @prev="()=>controller.clickPrev()"
        @next="()=>controller.clickNext()"
        @finish="()=>controller.clickFinish()">       
        <template #form>
            <component
                v-if="store.activeEditForm.codeName"
                :name="store.activeEditForm.name"
                :is="componentList[store.activeEditForm.codeName]"
                :actions="store.activeEditForm.actions"
                :context="store.context"
                :viewParams="store.viewParams"
                :pLoadingHelper="store.loadingHelper"
                :pViewCtx="store.viewCtx"
                :closeView="closeView"
                :openView="openView"
                :newView="newView"
                @ctrl-init="(name: string, ability: ICtrlAbility) => { handleCtrlInit(controller, name, ability) }"
                @ctrl-action="(name: string , action:any , data: IParam[]) => { handleCtrlAction(controller, name, action, data) }"
                @ctrl-destroy="(name: string , data: IParam) => { handleCtrlDestroy(controller, name, data) }" />
        </template>
    </AppWizardPanel>
    {{/if}}
</template>
<script setup lang="ts">
// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@WIZARDPANEL}}-wizard-panel/\{{spinalCase ctrl.codeName}}-wizard-panel.vue.hbs生成
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
import { model } from './{{spinalCase ctrl.codeName}}-wizard-panel-model';
import { AppWizardPanel } from '@components/widgets/wizard-panel';
import { {{pascalCase ctrl.name }}ControlVO } from './{{spinalCase ctrl.codeName}}-wizard-panel-vo';
import { WizardPanelActionType, WizardPanelController, IContext, IWizardPanelAbility, IWizardPanelControllerParams, IWizardPanelStore, IParam, ICtrlDataAction, IWizardPanelController, createUUID, ILoadingHelper, ICtrlAbility, IViewCtx } from '@/core';
import { useNavParamsBind, useEventBind, getCtrlClassNames, handleCtrlInit, handleCtrlAction, handleCtrlDestroy } from '@/hooks/use-ctrl';
import WizardPanelService from "@/core/modules/ctrl-service/wizard-panel-service";

{{#if ctrl.psDEEditForms}}
{{#each ctrl.psDEEditForms as | editForm |}}
import {{editForm.codeName}} from '@widgets/{{spinalCase editForm.psAppDataEntity.codeName}}/{{spinalCase editForm.codeName}}-form/{{spinalCase editForm.codeName}}-form.vue';
{{/each}}
{{/if}}

// 组件注册
const componentList:any = {
{{#if ctrl.psDEEditForms}}
{{#each ctrl.psDEEditForms as | editForm |}}
    {{editForm.codeName}},
{{/each}}
{{/if}}
}

{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    actions: ICtrlDataAction;
    "
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="WizardPanelActionType" ability="IWizardPanelAbility"}}

const controlID = createUUID();

const classNames = computed(() => {
    return getCtrlClassNames(model, props);
});

const ctrlService = new WizardPanelService<{{pascalCase ctrl.name}}ControlVO>({{pascalCase ctrl.name}}ControlVO, model.entityCodeName);

//  向导面板控制器
const params: IWizardPanelControllerParams<WizardPanelActionType, IWizardPanelAbility> = {
    name: props.name,
    model,
    evt,
    controlID,
    pLoadingHelper: props.pLoadingHelper,
    actions: props.actions,
    openView: props.openView,
    newView: props.newView,
    closeView: props.closeView,
    ctrlService: ctrlService,
    pViewCtx: props.pViewCtx,
    handler: (data: IWizardPanelStore) => { return reactive(data) }
};
{{> @macro/common/controller.hbs name="ctrl" IController="IWizardPanelController" store="IWizardPanelStore" ability="IWizardPanelAbility" controller="WizardPanelController"}}
</script>